"""
用户购买模型定义
"""

from typing import List, Optional
from pydantic import BaseModel, Field
import time


class UserPurchase(BaseModel):
    """用户购买基础模型"""

    user_id: int = Field(..., description="用户ID")
    book_id: int = Field(..., description="图书ID")
    price: float = Field(
        ..., ge=-1.0, description="购买价格，必须大于等于-1，图书免费时为-1"
    )
    created_at: int = Field(
        default_factory=lambda: int(time.time()), description="创建时间戳"
    )
    updated_at: int = Field(
        default_factory=lambda: int(time.time()), description="更新时间戳"
    )


class PurchaseRequest(BaseModel):
    """购买请求模型"""

    book_id: int = Field(..., description="图书ID")
    price: float = Field(
        ..., ge=-1.0, description="购买价格，必须大于等于-1，图书免费时为-1"
    )


class PurchaseResponse(BaseModel):
    """响应模型"""

    message: str = Field(..., description="响应消息")
    purchase_data: Optional[UserPurchase] = Field(None, description="购买数据")
